<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\report;

use app\enum\CommonEnum;
use app\model\report\ReportRecordListModel;
use app\service\report\ocean\FetchService as OF;
use app\service\report\kuaishou\FetchService as KF;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

final class ReportRecordFetchService extends ReportRecordBaseService
{
    public function __construct(ReportRecordListModel $listModel)
    {
        $this->pullModel = $listModel;
    }

    /**
     * 获取数据.
     *
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getData(): bool
    {
        if (! $this->setReportModel()) {
            return false;
        }
        if ($this->getReportAttr('media_id') == CommonEnum::OE_MEDIA) {
            $obj = new OF($this);
        } elseif ($this->getReportAttr('media_id') == CommonEnum::KS_MEDIA) {
            $obj = new KF($this);
        } else {
            return self::setError('未知媒体类型');
        }
        return $obj->getMediaData();
    }
}
